package pers.zc.activiti.thread.zhalan;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

/**
 * @description
 * @Author Lin FuYuan
 * @date 2020/4/24
 */
public class RunnableDemo implements Runnable {
    CyclicBarrier cyclicBarrier;
    private Integer integer;

    public RunnableDemo(CyclicBarrier cyclicBarrier,Integer integer){
        this.cyclicBarrier =cyclicBarrier;
        this.integer = integer;
    }
    @Override
    public void run() {
        try {
            Thread.sleep(1000);
            System.out.println(Thread.currentThread().getName());
        } catch (InterruptedException e) {
            e.printStackTrace();
        }finally{
            if(integer == 3){
                return;
            }
            int await = 0;
            try {
                await = cyclicBarrier.await();
            } catch (InterruptedException e) {
                e.printStackTrace();
            } catch (BrokenBarrierException e) {
                e.printStackTrace();
            }
            System.out.println(await);
        }
    }
}
